package com.toman;

import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.toman.Login.LoginActivity;
import com.toman.Util.SPUtils;
import com.toman.Util.ToastUtil;
import com.umeng.message.PushAgent;
import com.umeng.message.UTrack;

public class Dialog_Activity extends AppCompatActivity {

    //退出登录
    private SharedPreferences sp;
    private SharedPreferences.Editor edit;
    private MyApplication myApplication;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dialog_);
        //设置为全屏模式
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        myApplication = (MyApplication) getApplication();
        sp = myApplication.getSp();
        edit = sp.edit();
        TextView mLine_text = (TextView) findViewById(R.id.mLine_text);
//        mLine_text.setText(getIntent().getStringExtra("msg"));

        findViewById(R.id.mGologin).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                友盟解绑别名
                exit();
                //finish();
            }
        });
    }

    private void exit() {
        PushAgent pushAgent= myApplication.mPushAgent;
        String userid=(String) SPUtils.get(getApplicationContext(),"userid","");

        pushAgent.deleteAlias(userid, "toman", new UTrack.ICallBack(){
            @Override
            public void onMessage(boolean isSuccess, String message) {
                if (isSuccess){
                    ToastUtil.print("解绑成功："+message);
                }
                else {
                    ToastUtil.print("解绑失败："+message);

                }
            }
        });

        String phone=(String)SPUtils.get(getApplicationContext(),"phone","");
        String pwd= (String) SPUtils.get(getApplicationContext(),"pwd","");
        SPUtils.clear(getApplicationContext());
        SPUtils.put(getApplicationContext(),"phone",phone);
        SPUtils.put(getApplicationContext(),"pwd",pwd);

        //提交当前数据
        Intent intent = new Intent(Dialog_Activity.this, LoginActivity.class);
        startActivity(intent);
        myApplication.setType(99);
        finish();
    }


    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == event.KEYCODE_BACK) {
     exit();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }


}
